﻿<%@ WebHandler Language="C#" Class="TypeHandler" %>

using System;
using System.Web;
using SeDuce.BLL;
using SeDuce.Model;

public class TypeHandler : IHttpHandler {

    Lazy_Yu<TypeBLL> lazyTypeBLL = new Lazy_Yu<TypeBLL>(() => new TypeBLL());
    public TypeBLL LazyTypeBLL
    {
        get { return this.lazyTypeBLL.Value; }
    }
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        TypeData typeData = context.Request.Form["typedata"].ToString().FromJsonTo<TypeData>();

        JSONStatus status = new JSONStatus() { Status = "0" };
        if (typeData.TypeList.Count > 0)
        {
            if (!this.LazyTypeBLL.UpdateTypes(typeData.TypeList))
            {
                status.Status = "1";
            }
        }

        context.Response.Write(status.ToJSON());
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}